Learning Flex Basics (Part 2): Creating a Simple Calculator with Macromedia Flex
Robert Crooks
Table of Contents
- Introduction
- Building the Calculator
- Create the Application Object
- Add a Panel for the Calculator
- Add the Calculator Display
- Add a Grid to Lay Out the Buttons
- Add the Calculator Buttons
- Create the CalculatorController Class
- Add Properties to the Controller Class
- Add Controller Methods
- Instantiate the CalculatorController Class
- Complete Code Listing for calculator.mxml
- Complete Code Listing for CalculatorController.as
- Where to Go From Here
In this tutorial, you will build a working calculator in Macromedia Flex. Although the calculator is simple—it just adds, subtracts, multiplies, and divides—building it will enable you to work with several essential building blocks for Flex applications.
This tutorial is the second part in a four-part series written by Robert Crooks of the Macromedia Customer Training group:
- Learning Flex Basics (Part 1): Creating Your First Flex Application
- Learning Flex Basics (Part 3): Working with Containers
- Learning Flex Basics s(Part 4): Working with Data Models
If you prefer, you can download the entire set of tutorials.
-
Learning
Flex Series (Parts 1-4) (144 KB)
If you like what you see and want to get more experience with Flex, Macromedia Customer Training offers Fast Track to Macromedia Flex, a two-day onsite training course to jump-start Flex development in your organization. Now let's get started!
What You Will Learn
- How to use the Application tag.
- How to use a Panel container.
- How to use Label controls.
- How to use Button controls.
- How to use a Grid container.
- How to create an ActionScript controller class for an MXML file.
Requirements
To complete this tutorial you will need to install the following software and files:
Macromedia Flex
(Installed and running on any server and platform supported by Flex. Note that the Flex trial is available on CD from the Macromedia store for $8.99. To learn more about the Flex trial, please read the Flex Frequently Asked Questions.)
Dreamweaver MX 2004 or a text editor that you can use to write XML and ActionScript code (a basic text editor such as Notepad is adequate)
Solution files for the tutorial:
calculator.zip
(contains the complete source code for calculator.mxml and
CalculatorController.as in this article)
Prerequisite knowledge:
- Read A Brief Overview of Flex.
- You must know how to browse a Flex application.
- You should have completed Learning Flex Basics (Part 1): Creating Your First Flex Application, or have a basic understanding of how Flex applications work.